/*
 *Copyright (c) 2024 Black Sesame Technologies
 *
 *Licensed under the Apache License, Version 2.0 (the "License");
 *you may not use this file except in compliance with the License.
 *You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 *Unless required by applicable law or agreed to in writing, software
 *distributed under the License is distributed on an "AS IS" BASIS,
 *WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *See the License for the specific language governing permissions and
 *limitations under the License.
*/

#ifndef HSCG_INTERFACECANTYPES_H
#define HSCG_INTERFACECANTYPES_H

#ifdef __cplusplus
extern "C" {
#endif



/*==================================================================================================
 *                                        INCLUDE FILES
 * 1) system and project includes
 * 2) needed interfaces from external units
 * 3) internal and external interfaces from this unit
 ==================================================================================================*/
#include "StandardTypes.h"
#include "Hscg_InterfaceConfig.h"

/*==================================================================================================
 *                              SOURCE FILE VERSION INFORMATION
 ==================================================================================================*/

/*==================================================================================================
 *                                     FILE VERSION CHECKS
 ==================================================================================================*/

/*==================================================================================================
 *                                          CONSTANTS
 ==================================================================================================*/

/*==================================================================================================
 *                                      DEFINES AND MACROS
 ==================================================================================================*/
#if defined(_lint)
    /* Workaround for PC-LINT not to see attribute keyword */
    /* @violates @ref Hscg_InterfaceCanTypes_h_REF_1 Violates MISRA 2012 Required
    * Rule 21.1, only for PC-LINT analyse */
    /* @violates @ref Hscg_InterfaceCanTypes_h_REF_2 Violates MISRA 2012 Required
    * Rule 4.9, only for PC-LINT analyse */
    #define __HSCG__ALIGNED__PACKED__
    /* Common defines for standard version. Meant to be used by PC-LINT*/
    #define CANETH_ENABLE ON
    #define CAN2CAN_ENABLE ON
    #define LIN_ENABLE ON
    #define AF_ENABLE ON
#else
    #define __HSCG__ALIGNED__PACKED__ __attribute__((aligned(4), packed))
#endif
/*==================================================================================================
 *                                CONTROLLER OPTIONS
 ==================================================================================================*/
/**
 * @brief Controller option used by the initialization command in order to
 * inform HSCG firmware that a specific controller shall be initialized.
 * See \link Hscg_Can_InitCmdType \endlink
 */
#define HSCG_CAN_CONTROLLERCONFIG_CTRL_EN_U32 ((uint32)0x10000000U)
/**
 * @brief CAN controller option used to enable reporting of the Protocol
 * Exception errors.
 * See \link Hscg_Can_GetStatusCmdType \endlink
 */
#define HSCG_CAN_CONTROLLERCONFIG_PE_EN_U32 ((uint32)0x00040000U)
/** @brief CAN controller option used to enable Timestamp feature. */
#define HSCG_CAN_CONTROLLERCONFIG_TST_END_U32 ((uint32)0x00080000U)
/**
 * @brief CAN controller option used to enable Timestamp feature at the start
 * of the CAN frame.
 */
#define HSCG_CAN_CONTROLLERCONFIG_TST_START_U32 ((uint32)0x00000080U)
/**
 * @brief CAN controller option used to enable Timestamp feature in the start of
 * frame for classical CAN frames and in the res bit for CAN FD frames.
 */
#define HSCG_CAN_CONTROLLERCONFIG_TST_FD_U32 ((uint32)0x00000040U)
/** @brief CAN controller option used to enable Listen-Only mode. */
#define HSCG_CAN_CONTROLLERCONFIG_LOM_EN_U32 ((uint32)0x00100000U)
/** @brief CAN controller option used to enable internal LoopBack mode. */
#define HSCG_CAN_CONTROLLERCONFIG_LPB_EN_U32 ((uint32)0x00200000U)
/** @brief CAN controller option used to enable self-reception mode. */
#define HSCG_CAN_CONTROLLERCONFIG_SRX_EN_U32 ((uint32)0x00400000U)

/**
 * @brief Number of interfaces used for interrupt reporting
 * (one per channel) + number of polling classes.
 */
#define HSCG_CAN_RX_TX_INTERFACES                                              \
    ((uint8)(HSCG_CAN_CONFIG_MAXCTRL_COUNT + HSCG_CAN_MAX_POLLING_CLASSES))
/**
 * @brief Default value in the transmission request informing HSCG that tx
 * confirmation is not needed for that frame.
 */
#define HSCG_CAN_ACK_DISABLED ((uint8)0xADU)
#define HSCG_CAN_PARAM_NOT_USED ((uint8)0xFFU)

/*==================================================================================================
                 DEFINES SHARED BETWEEN HOST AND HSCG
==================================================================================================*/
/** @brief Frame DLC field mask. */
#define HSCG_CAN_MB_DLC_MASK_U32 ((uint32)0x0000000FU)
/** @brief Frame ID field mask. */
#define HSCG_CAN_MB_ID_MASK_U32 ((uint32)0x1FFFFFFFU)
/** @brief Frame FDF field mask. */
#define HSCG_CAN_MB_FDF_U32 ((uint32)0x00008000U)
/** @brief Frame BRS field mask. */
#define HSCG_CAN_MB_BRS_U32 ((uint32)0x00010000U)
/** @brief Frame ESI field mask. */
#define HSCG_CAN_MB_ESI_U32 ((uint32)0x00020000U)
/** @brief Frame IDE field mask. */
#define HSCG_CAN_MB_IDE_U32 ((uint32)0x40000000U)
/** @brief Frame RTR field mask. */
#define HSCG_CAN_MB_RTR_U32 ((uint32)0x80000000U)
/** @brief Frame standard ID field mask. */
#define HSCG_CAN_MB_IDSTD_MASK_U32 ((uint32)0x1FFC0000U)
/** @brief Frame extended ID field mask. */
#define HSCG_CAN_MB_IDEXT_MASK_U32 ((uint32)0x0003FFFFU)
/** @brief Routing feature default configuration. */
#define HSCG_CAN_ROUTING_OPTION_DEFAULT_CONFIG ((uint32)0x00000000U)
/** @brief Routing feature mask for non-converting frame. */
#define HSCG_CAN_ROUTING_NOCHANGE ((uint32)0x00000001U)
/** @brief Routing feature mask for converting frame (CANFD->CAN). */
#define HSCG_CAN_ROUTING_CAN ((uint32)0x00000002U)
/** @brief Routing feature mask for converting frame (CAN->CANFD). */
#define HSCG_CAN_ROUTING_CANFD ((uint32)0x00000004U)
/** @brief Routing feature mask for id remapping. */
#define HSCG_CAN_ROUTING_ID_REMAPPING_EN ((uint32)0x00000008U)

/** @brief Shift value for extracting FD flag  from CAN frame. */
#define HSCG_CAN_MB_FDF_SHIFT_U32 ((uint32)15U)
/** @brief Shift value for extracting Baud Rate Switch flag from CAN frame. */
#define HSCG_CAN_MB_BRS_SHIFT_U32 ((uint32)16U)
/** @brief Shift value for extracting ESI flag feature from CAN frame. */
#define HSCG_CAN_MB_ESI_SHIFT_U32 ((uint32)17U)
/** @brief Shift value for extracting frame ID from CAN frame. */
#define HSCG_CAN_MB_IDSTD_SHIFT_U32 ((uint32)18U)
/** @brief Shift value for extracting IDE flag from CAN frame. */
#define HSCG_CAN_MB_IDE_SHIFT_U32 ((uint32)30U)
/** @brief Shift value for extracting RTR flag from CAN frame. */
#define HSCG_CAN_MB_RTR_SHIFT_U32 ((uint32)31U)

/** @brief Shift value for extracting precalculated length from CAN frame. */
#define HSCG_CAN_MB_PRECALC_LEN_SHIFT_U32 ((uint32)24U)

/** @brief Constant used to identify a reserved mask id. */
#define HSCG_CAN_FULLCAN_MASK_U32 (uint32)0xFFFFFFFFU

/*==================================================================================================
*                                             ENUMS
==================================================================================================*/
/*==================================================================================================
 *                                             ENUMS
 ==================================================================================================*/
/**
 * @brief CAN firmware error values.
 *
 * CAN error values as they are reported by the HSCG firmware. Some of them are
 * channel related and other are platform related.
 **/
#if defined(LDRA) || defined(_lint)
    /* Workaround for PC-LINT and LDRA tools not to see packed keyword */
    /* @violates @ref Hscg_InterfaceFwMgr_h_REF_1 Violates MISRA 2012 Required
    * Rule 21.1, only for PC-LINT analyse */
    /* @violates @ref Hscg_InterfaceFwMgr_h_REF_2 Violates MISRA 2012 Required
    * Rule 4.9, only for PC-LINT analyse */
    #define __HSCG__PACKED__
#else
    #define __HSCG__PACKED__ __attribute__((packed))
#endif

typedef enum __HSCG__PACKED__
{
    /** @brief CAN firmware error: TXACK FIFO is full. */
    HSCG_ERROR_TXACK_FIFO_FULL = 1U,
    /** @brief CAN firmware error: RXOUT FIFO is full. */
    HSCG_ERROR_RXOUT_FIFO_FULL,
    /** @brief CAN firmware error: HW FIFO inside HSCG is empty. */
    HSCG_ERROR_HW_FIFO_EMPTY,
    /** @brief CAN firmware error: HW FIFO inside HSCG is full. */
    HSCG_ERROR_HW_FIFO_FULL,
    /** @brief CAN firmware error: SW FIFO inside HSCG is empty. */
    HSCG_ERROR_SW_FIFO_EMPTY,
    /** @brief CAN firmware error: SW FIFO inside HSCG is full. */
    HSCG_ERROR_SW_FIFO_FULL,
    /** @brief CAN firmware error: Message buffer is not avaialable. */
    HSCG_ERROR_MB_NOTAVAILABLE,
    /**
     * @brief CAN firmware error: CAN protocol error due to inability to get
     * out from the freeze mode.
     */
    HSCG_ERROR_BCAN_FRZ_EXIT,
    /**
     * @brief CAN firmware error: CAN protocol error due to inability to
     * synchronize on the bus.
     */
    HSCG_ERROR_BCAN_SYNC,
    /**
     * @brief CAN firmware error: CAN protocol error due to inability to
     * enter in freeze mode.
     */
    HSCG_ERROR_BCAN_FRZ_ENTER,
    /**
     * @brief CAN firmware error: CAN protocol error due to inability to
     * enter in low-power mode.
     */
    HSCG_ERROR_BCAN_LPM_EXIT,
    /**
     * @brief CAN firmware error: CAN protocol error due to inability to
     * enter in soft reset.
     */
    HSCG_ERROR_BCAN_SRT_ENTER,
    /**
     * @brief CAN firmware error: CAN protocol error due to inability to
     * enter in soft reset.
     */
    HSCG_ERROR_BCAN_UNKNOWN_ERROR,
    /**
     * @brief CAN firmware error: ACKERR indicates that an acknowledge error
     * has been detected by the transmitter node.
     */
    HSCG_ERROR_BCAN_ACKERR,
    /**
     * @brief CAN firmware error: CRCERR indicates that a CRC error has been
     * detected by the receiver node in a CAN frame.
     */
    HSCG_ERROR_BCAN_CRCERR,
    /**
     * @brief CAN firmware error: BIT0ERR indicates when an inconsistency
     * occurs between the transmitted and the received bit in a CAN frame.
     */
    HSCG_ERROR_BCAN_BIT0ERR,
    /**
     * @brief CAN firmware error: BIT1ERR indicates when an inconsistency
     * occurs between the transmitted and the received bit in a CAN frame.
     */
    HSCG_ERROR_BCAN_BIT1ERR,
    /**
     * @brief CAN firmware error: FRMERR indicates that a form error has
     * been detected by the receiver node in a CAN frame - a fixed-form bit
     * field contains at least one illegal bit.
     */
    HSCG_ERROR_BCAN_FRMERR,
    /**
     * @brief CAN firmware error: STFERR indicates that a stuffing error has
     * been detected by the receiver node in a CAN frame.
     */
    HSCG_ERROR_BCAN_STFERR,
    /**
     * @brief CAN firmware error: DataLost event caused by BCAN RX Fifo
     * Overrun.
     */
    HSCG_ERROR_BCAN_RXFIFO_OVERRUN,
    /**
     * @brief CAN firmware error: Reports data lost event due to resources
     * exceeded after the frame was received
     */
    HSCG_ERROR_DATA_LOST,
    /** @brief CAN firmware error: TXLUT acclerator is full. */
    HSCG_ERROR_TXLUT_FULL,
    /** @brief CAN firmware error: Error during command processing. */
    HSCG_ERROR_CMD_PROCESSING,
    /** @brief CAN firmware error: Error regarding RXLUT hardware. */
    HSCG_ERROR_RXLUT_SLOW_SEARCH,
    /** @brief CAN firmware error: Error regarding RXLUT hardware. */
    HSCG_ERROR_RXLUT_ACCESS_MODE,
    /** @brief CAN firmware error: Error regarding RXLUT hardware. */
    HSCG_ERROR_RXLUT_SEARCH_MODE,
    /** @brief CAN firmware error: Error regarding RXLUT hardware. */
    HSCG_ERROR_RXLUT_SLOW_OPERATION,
    /** @brief CAN firmware error: Error regarding RXLUT hardware. */
    HSCG_ERROR_RXLUT_INCOMPLETE_OP,
    /** @brief CAN firmware error: Error regarding RXLUT hardware. */
    HSCG_ERROR_RXLUT_OPERATING_MODE,
    /** @brief CAN firmware error: Error regarding RXLUT hardware. */
    HSCG_ERROR_RXLUT_INIT_SLOW_OP,
    /** @brief CAN firmware error: Error regarding RXLUT hardware. */
    HSCG_ERROR_RXLUT_DEINIT_SLOW_OP,
    /** @brief CAN firmware error: Error regarding RXLUT hardware. */
    HSCG_ERROR_RXLUT_INIT_OPERATING_MODE,
    /** @brief CAN firmware error: Error regarding RXLUT hardware. */
    HSCG_ERROR_RXLUT_DEINIT_OPERATING_MODE1,
    /** @brief CAN firmware error: Error regarding RXLUT hardware. */
    HSCG_ERROR_RXLUT_DEINIT_OPERATING_MODE2,
    /** @brief CAN firmware error: Error regarding bus off event. */
    HSCG_ERROR_HARDWARE_BUSOFF,
    /** @brief CAN firmware error: Controller is not ready. */
    HSCG_ERROR_CTRL_NOT_READY,
    /** @brief CAN firmware error: Error regarding bus off. */
    HSCG_ERROR_BUSOFF,
    /** @brief CAN firmware error: Logging fifo is full. */
    HSCG_ERROR_FIFO_LOG_FULL,
    /**
     * @brief CAN firmware error: Error reported due to CAN2CAN routing
     * error.
     */
    HSCG_ERROR_CAN2CAN,
    /**
     * @brief CAN firmware error: Error reported due to wrong command
     * parameters received from host.
     */
    HSCG_ERROR_COMMAND_PARAM,
    /**
     * @brief CAN firmware error: Error reported due to the rx core not
     * responding.
     */
    HSCG_ERROR_COMMAND_RXPPE_NORESPONSE,
    /**
     * @brief CAN firmware error: Error reported due to the AF core not
     * responding.
     */
    HSCG_ERROR_COMMAND_AF_NORESPONSE,
    /**
     * @brief CAN firmware error: Error reported because the controller is
     * not stopped.
     */
    HSCG_ERROR_COMMAND_DEINIT_NOTSTOP,
    /**
     * @brief CAN firmware error: Error reported because the host didn't
     * read all the RX tokens (indexes in fifos). HSCG waits for indexes
     * to be read and returned.
     */
    HSCG_ERROR_RXTOKENS_UNRETURNED,
    /**
     * @brief CAN firmware error: Error reported because the host didn't
     * read all the ACKs (indexes in fifos). HSCG waits for indexes to be
     * read.
     */
    HSCG_ERROR_TXACK_NOT_READ,
    /**
     * @brief CAN firmware error: Error reported because the requested
     * command is not in the list of supported commands.
     */
    HSCG_ERROR_COMMAND_NOTSUPPORTED,
    /**
     * @brief CAN firmware error: Error reported because command is not
     * validated by the command flow.
     */
    HSCG_ERROR_COMMAND_NOTVALIDATED,
    /**
     * @brief CAN firmware error: Error reported because the requested
     * command is correct but it not accepted.
     */
    HSCG_ERROR_COMMAND_NOTACCEPTED,
    /**
     * @brief CAN firmware error: Error reported because the requested
     * command parameters are invalid.
     */
    HSCG_ERROR_COMMAND_INVALID_PARAMS,
    /** @brief CAN firmware error: Controller is not started. */
    HSCG_ERROR_CTRL_NOT_STARTED,
    /**
     * @brief CAN firmware error: Reports frame accepted, but not delivered
     * to host because of filters misconfiguration.
     */
    HSCG_ERROR_FRAME_NOT_DELIVERED,
    /**
     * @brief CAN firmware error: Reports frame accepted, but not delivered
     * to AF destination because of full fifo.
     */
    HSCG_ERROR_FRAME_NOT_DELIVERED_TO_AF,
    /**
     * @brief CAN firmware error: Reports frame accepted, but not delivered
     * to host due to lack of descriptors in sw fifo.
     */
    HSCG_ERROR_FRAME_NOT_DELIVERED_TO_HOST,
    /**
     * @brief CAN firmware error: Reports detection of lost indexes in
     * RX-DTE subsystem.
     */
    HSCG_ERROR_LOST_INDEXES,
    /**
     * @brief CAN firmware error: Error reported because there are no
     * filters avaialable to be set for a specific controller.
     */
    HSCG_ERROR_FILTERS_FULL,
    /**
     * @brief CAN firmware error: The filter pointed by the related address
     * is not used by the related controller.
     */
    HSCG_ERROR_FILTERS_NOTEXIST,
    /** @brief CAN firmware error: There are no free configuration filters.
     */
    HSCG_ERROR_FILTERS_MASK_EMPTY,
    /** @brief CAN firmware error: There are no free configuration filters.
     */
    HSCG_ERROR_FILTERS_RANGE_EMPTY,
    /** @brief CAN firmware error: There are no free exact match filters. */
    HSCG_ERROR_FILTERS_EM_EMPTY,
    /** @brief CAN firmware error: The index return by host is not valid. */
    HSCG_ERROR_IDX_NOT_VALID_HOST,
    /** @brief CAN firmware error: The index return by logging is not valid.
     */
    HSCG_ERROR_IDX_NOT_VALID_LOG,
    /**
     * @brief CAN firmware error: The host core which sent a free RX
     * descriptor index to LHSCG is invalid.
     */
    HSCG_ERROR_INVALID_HOST_CORE,
    /**
     * @brief CAN firmware error: Reports frame accepted, but not delivered
     * to HSE because of full fifo.
     */
    HSCG_ERROR_RXFRAME_NOT_DELIVERED_TO_HSE,
    /**
     * @brief CAN firmware error: TX frame was not delivered to HSE because
     * of full fifo.
     */
    HSCG_ERROR_TXFRAME_NOT_DELIVERED_TO_HSE,
    /**
     * @brief CAN firmware error: Rx frame was dropped because it is not
     * authentic.
     */
    HSCG_ERROR_RXFRAME_AUTH_ERROR,
    /**
     * @brief CAN firmware error: core received an invalid request from
     * TX core.
     */
    HSCG_ERROR_INVALID_REQUEST_FROM_TX,
    /**
     * @brief CAN firmware error: core received an invalid request from
     * RX core.
     */
    HSCG_ERROR_INVALID_REQUEST_FROM_RX,
    /** @brief CAN firmware error: RX Software FIFO is empty. */
    HSCG_ERROR_RX_SW_FIFO_EMPTY,
    /** @brief AF error : error communicating with PFE */
    HSCG_ERROR_PFEIF,
    /** @brief AF error : error communicating with HSE */
    HSCG_ERROR_HSEIF,
    /**
     * @brief Generic firmware code: Command was executed successfully by
     * HSCG Firmware.
     */
    HSCG_FW_SUCCESS,    /* 71 */
    /**
     * @brief Generic firmware error: During command execution it was
     * detected an error condition.
     */
    HSCG_FW_ERROR,      /* 72 */
    /**
     * @brief Generic firmware code: Default value of command return
     * status, set by the host before to send it to HSCG firmware.
     */
    HSCG_FW_NOTRUN,
    /**
     * @brief CAN firmware error: Internal Descriptor was not returned
     * to the source.
     */
    HSCG_ERROR_INTERNALDESC_NOT_RETURNED,
    /**
     * @brief CAN firmware error: Internal Descriptor was not delivered
     * to the destination.
     */
    HSCG_ERROR_INTERNALDESC_NOT_DELIVERED,
    /**
     * @brief CAN firmware error: Internal Descriptor is not available.
     */
    HSCG_ERROR_INTERNALDESC_NOTAVAIL,
    /**
     * @brief CAN firmware error: Internal Descriptor software FIFO is full.
     */
    HSCG_ERROR_INTERNALDESC_FIFO_FULL,
    /** @brief CAN firmware error: Message Buffer is not available. */
    HSCG_ERROR_MB_NOTAVAIL,
    /** @brief CAN firmware error: Message Buffer software FIFO is full. */
    HSCG_ERROR_MB_FIFO_FULL,
    /**
     * @brief CAN firmware error: Maximum number of Tx MB per controller for
     * AF is reached.
     */
    HSCG_ERROR_NO_MB_AVAILABLE,
    /** @brief CAN firmware error: Unknown source of the request. */
    HSCG_ERROR_UNKNOWN_SRC,
    /** @brief CAN firmware error: Unknown destination of the request. */
    HSCG_ERROR_UNKNOWN_DEST,
    /** @brief CAN firmware error: Unknown request. */
    HSCG_ERROR_UNKNOWN_REQUEST,
    /** @brief CAN firmware error: Conversion error for CAN2CAN. */
    HSCG_ERROR_CONVERSION,
    /**
     * @brief CAN firmware error: AbortMB request failed due to no pending
     * transmission that can be aborted.
     */
    HSCG_ERROR_NO_MB_TO_ABORT,
    /**
     * @brief CAN firmware error: Index not recovered from DTE after Stop
     * or busoff event.
     */
    HSCG_ERROR_INDEX_NOT_RECOVERED
} Hscg_Fw_ReturnType;
/**
 * @brief Notification IDs used to interface with HSCG.
 *
 * Notifications send by HSCG to host core.
 **/
typedef enum __HSCG__PACKED__
{
    /** @brief No error. */
    HSCG_CAN_NOTIF_NOERROR = 0U,
    /** @brief Error related to the common platform area. */
    HSCG_CAN_NOTIF_PLATFORMERROR,
    /** @brief Error related to a specific channel.*/
    HSCG_CAN_NOTIF_CHANNELERROR,
    /** @brief Notification related to changing CAN controller mode.*/
    HSCG_CAN_NOTIF_CTRLMODE,
} Hscg_Can_NotificationIdType;

/**
 * @brief Command IDs used to interface with HSCG.
 *
 * Some of those commands are send by the host to HSCG module and others are
 * sent by HSCG module to the host.
 **/
typedef enum __HSCG__PACKED__
{
    /** @brief Host initializes HSCG module. */
    HSCG_CAN_CMD_INIT = 0U,
    /** @brief Host deinitializes a specific CAN controller. */
    HSCG_CAN_CMD_DEINIT,
    /** @brief Host sets a baud rate for a specific CAN controller.*/
    HSCG_CAN_CMD_SETBAUDRATE,
    /** @brief Host checks the state for a specific CAN controller.*/
    HSCG_CAN_CMD_GETCONTROLLERMODE,
    /** @brief Host changes the state for a specific CAN controller.*/
    HSCG_CAN_CMD_SETCONTROLLERMODE,
    /**
     * @brief HSCG deliver to the host the content of all status register
     * of CAN controller.
     */
    HSCG_CAN_CMD_GETSTATUS,
    HSCG_CAN_CMD_SET_MB_FILTER,
    HSCG_CAN_CMD_SET_ENHANCED_FIFO_FILTER,
    /** @brief Request version string from FW.*/
    HSCG_CAN_CMD_GETFWVERSION,
    /** @brief Host request for platform initialization.*/
    HSCG_CAN_CMD_INIT_PLATFORM,
    /** @brief Host request for platform deinitialization.*/
    HSCG_CAN_CMD_DEINIT_PLATFORM,
    HSCG_CAN_CMD_START,
    HSCG_CAN_CMD_STOP

} Hscg_Can_CommandIdType;

/**
 * @brief CAN frame ID type.
 *
 * It specify the CAN frame ID type based on it's length as it is
 * defined by CAN specification.
 **/
typedef enum __HSCG__PACKED__
{
    /** @brief Extended ID (29 bits) */
    HSCG_CAN_EXTENDED = 0U,
    /** @brief Standard ID (11 bits) */
    HSCG_CAN_STANDARD,
    /** @brief Mixed ID (29 bits) */
    HSCG_CAN_MIXED
} Hscg_Can_IdLengthType;

/**
 * @brief Requested transitions of a CAN controller.
 *
 * Those controller state transitions are requested by the host in a specific
 * order.
 **/
typedef enum __HSCG__PACKED__
{
    /** @brief Request transition from START state into STOP state. */
    HSCG_CAN_T_STOP = 0U,
    /** @brief Request transition from STOP state into START state. */
    HSCG_CAN_T_START,
} Hscg_Can_StateTransitionType;

/**
 * @brief CAN controller states.
 *
 * CAN controller states as they are reported by the HSCG firmware as a result
 * of state transition requests.
 **/
typedef enum __HSCG__PACKED__
{
    /** @brief Controller is uninitialised (default) */
    HSCG_CAN_UNINIT_CTRL = 0U,
    /**
     * @brief Controller is in a pending state of unitialization, waiting
     * for the resources to be restored (e.g Rx tokens)
     */
    HSCG_CAN_UNINIT_CTRL_PENDING,
    /** @brief Controller is stopping, but not offline yet */
    HSCG_CAN_STOP_PENDING,
    /**
     * @brief Controller is in the BUSOFF_PENDING state which means that it
     * does not do any bus transactions.
     */
    HSCG_CAN_BUSOFF_PENDING,
    /**
     * @brief Controller is in the STOPPED state which means that it does
     * not do any bus transactions.
     */
    HSCG_CAN_STOPPED,
    /** @brief Controller is starting, but cannot do bus transactions yet.*/
    HSCG_CAN_START_PENDING,
    /**
     * @brief Controller is in the STARTED state which means that it do bus
     * transactions.
     */
    HSCG_CAN_STARTED,
    /**
     * @brief Controller is in the IDLE state. This state is not used
     * by HSCG module.
     */
    HSCG_CAN_IDLE,
    /**
     * @brief Controller is in state when the common components of the
     * platform are not initialized.
     */
    HSCG_CAN_UNINIT_PLATFORM
} Hscg_Can_CtrlStateType;

/**
 * @brief CAN firmware components IDs.
 *
 * CAN firmware components IDs used to identify the component which generated a
 * specific error.
 **/
typedef enum __HSCG__PACKED__
{
    /** @brief CAN TX firmware component. */
    HSCG_TX = 101U,
    /** @brief CAN RX firmware component. */
    HSCG_RX,
    /** @brief CAN DTE firmware component. */
    HSCG_DTE,
    /** @brief CAN FRPE firmware component. */
    HSCG_FRPE,
    /** @brief CAN2CAN TX firmware component. */
    HSCG_CAN2CAN_TX,
    /** @brief CAN2CAN RX firmware component. */
    HSCG_CAN2CAN_RX,
    /** @brief CAN2CAN FRPE firmware component. */
    HSCG_CAN2CAN_FRPE,
    /** @brief AF ETH2CAN TX firmware component. */
    HSCG_AF_ETH_TX,
    /** @brief AF CAN2ETH RX firmware component. */
    HSCG_AF_ETH_RX,
    /** @brief AF CAN2ETH or ETH2CAN FRPE firmware component. */
    HSCG_AF_ETH_FRPE,
    /** @brief HSE TX firmware component. */
    HSCG_AF_HSE_TX,
    /** @brief HSE RX firmware component. */
    HSCG_AF_HSE_RX,
    /** @brief HSE FRPE firmware component. */
    HSCG_AF_HSE_FRPE,
    /** @brief AF TX  firmware component. */
    HSCG_AF_TX,
    /** @brief AF RX  firmware component. */
    HSCG_AF_RX,
    /** @brief AF FRPE firmware component. */
    HSCG_AF_FRPE
} Hscg_Can_ModuleType;

/**
 * @brief CAN Logging options.
 *
 * CAN options for logging frames feature.
 **/
typedef enum __HSCG__PACKED__
{
    /** @brief Logging of CAN frame is disabled.*/
    HSCG_AF_LOGGING_DISABLED = 1U,
    /** @brief Logging of CAN frame is enabled.*/
    HSCG_AF_LOGGING_ENABLED
} Hscg_Af_LoggingOptionsType;

typedef enum __HSCG__PACKED__
{
    /** @brief Logging of CAN frame is disabled.*/
    HSCG_AF_HOSTRECEIVE_DISABLED = 1U,
    /** @brief Logging of CAN frame is enabled.*/
    HSCG_AF_HOSTRECEIVE_ENABLED
} Hscg_Can_HostReceiveOptionsType;

typedef enum __HSCG__PACKED__
{
    /** @brief Authentication of CAN frame is disabled.*/
    HSCG_AF_AUTHENTICATION_DISABLED = 1U,
    /** @brief Authentication of CAN frame is enabled.*/
    HSCG_AF_AUTHENTICATION_ENABLED,
    HSCG_AF_AUTHENTICATION_NOT_SUPPORTED
} Hscg_Af_AuthenticationOptionsType;

/**
 * @brief RXLUT entries type
 *
 * Specifies the type of entry in the table.
 **/
typedef enum __HSCG__PACKED__
{
    /** @brief Exact match entry type. */
    HSCG_CAN_ENTRY_EXACT_MATCH = 0U,
    /** @brief Masked match entry type. */
    HSCG_CAN_ENTRY_CFG_MASKED,
    /** @brief Range match entry type. */
    HSCG_CAN_ENTRY_CFG_RANGED,
} Hscg_Can_EntryType;

/**
 * @brief Type of Advanced Feature(AF) rule.
 *
 * Specifies the type of entry in the destination rule table.
 **/
typedef enum __HSCG__PACKED__
{
    /** @brief Destination rule type used for Can2Can use case. */
    CAN_AF_CAN2CAN = 0U,
    /** @brief Destination rule type used for Can2Eth use case. */
    CAN_AF_CAN2ETH
} Hscg_Af_RuleIdType;

/**
 * @brief Initialization status of the controllers.
 *
 * Initialization status of the controllers.
 * See \link Hscg_Can_InitPlatformCmdType \endlink.
 **/
typedef enum __HSCG__PACKED__
{
    /** @brief Entity is initialised */
    INITIALIZED = 1U,
    /** @brief Entity is uninitialised (default) */
    UNINITIALIZED = 2U
} Hscg_Can_StatusType;

/**
 * @brief Processing type of a specific error
 *
 * Processing type of a specific error.
 * See \link Hscg_Can_InitPlatformCmdType \endlink.
 **/
typedef enum __HSCG__PACKED__
{
    /** @brief HSCG Firmware does not report the error */
    IGNORE = 1U,
    /**
     * @brief HSCG Firmware reports the error through the notification table
     * corresponding to processing type configured by host
     */
    NOTIF_FIFO0,
    /**
     * @brief HSCG Firmware reports the error through the notification table
     * corresponding to processing type configured by host
     */
    NOTIF_FIFO1,
} Hscg_Can_ErrorProcessingType;

/**
 * @brief AbortMB Type
 *
 * Specifies the type of AbortMB command. It can be either Single MB
 * abort or All MBs abort
 **/
typedef enum __HSCG__PACKED__
{
    /** @brief Request aborting of a single MB with a specific MB tag. */
    ABORT_ONLY_ONE_MB = 0U,
    /** @brief Request aborting of all the MBs with a specific MB tag. */
    ABORT_ALL_MB
} Hscg_Can_AbortMbType;

/*==================================================================================================
*                                STRUCTURES AND OTHER TYPEDEFS
==================================================================================================*/

/*
 * These structure must be kept as they are because BCAN is
 * sending data in this format !
 */
/**
 * @brief CAN message buffer.
 *
 * CAN message buffer is a memory area placed in the shared memory
 * which is used by the HSCG firmware to receive/transmit from/to BCAN
 * controller. HSCG firmware transmit/receive the frame in a word by word way so
 * the content of the 4 structure fields contains the frame fields as they are
 * described in the picture from below. For the reception process the HSCG
 * firmware store inside message buffer frame the time stamp read from the
 * hardware CAN controller.
 *
 * \image latex rx_mb.JPG "HSCG message buffer structure." width=17cm
 *
 * @pre Before to use any message buffer it is needed to initialize, configure
 * and start a CAN controller
 **/
typedef struct
{
    /**
     * @brief INPUT/OUTPUT: The first word of a frame as it is
     * expected/provided by the CAN controller.
     */
    uint32 u32Word0;
    /**
     * @brief INPUT/OUTPUT: The second word of a frame as it is
     * expected/provided by the CAN controller.
     */
    uint32 u32Word1;
    /**
     * @brief INPUT/OUTPUT: Frame payload needed for the maximum
     * payload size case.
     */
    uint8 u8Payload[HSCG_CAN_CONFIG_PAYLOAD_MAX_SIZE];
    /**
     * @brief INPUT: Time stamp of the received frames.It is not used
     * for the transmitted frames.
     */
    uint32 u32Timestamp;
} __HSCG__ALIGNED__PACKED__ Hscg_Can_MbType;

/**
 * @brief Reception message buffer descriptor.
 *
 * Reception message buffer descriptor is a memory area placed in the shared
 * memory which is written by the HSCG firmware with the specific runtime info
 * needed by the host software.(e.g.matching filter ID ). Also it includes an
 * index to a CAN message buffer allocated during initialization to each
 * descriptor. After reception, the host shall copy the content of the reception
 * message buffer descriptor and the referred message buffer by this descriptor
 * from the shared memory into the host memory in order to be processed later by
 * the host software and to allow the current message buffer descriptor to be
 * used by HSCG firmware for the reception of a new frame.
 *
 * @pre Before to use any receive message buffer descriptor it is needed to
 * initialize, configure and start a CAN controller
 **/
typedef struct
{
    /**
     * @brief OUTPUT: Filter identifier resulted at the end of filtering
     * process.
     *
     * This field is completed by the HSCG filtering mechanism with a value
     * which was configured during initialization time.
     * It is used in order to map a received frame to a specific filter
     * defined by the host.
     */
    uint16 u16FilterId;
    /**
     * @brief OUTPUT: Index to the CAN message buffer.
     * See \link Hscg_Can_MbType \endlink
     */
    uint16 u16MbFrameIdx;
} __HSCG__ALIGNED__PACKED__ Hscg_Can_RxMbDescriptorType;

/**
 * @brief Transmission message buffer descriptor.
 *
 * Transmission message buffer descriptor is a memory area placed in the shared
 * memory which is written by the host software with other additional info
 * (e.g. frame tag IDs) which is send back to the host by the HSCG firmware as
 * acknowledge information. Those internal tags are not changed/used by the
 * HSCG firmware.
 *
 * @pre Before to use any transmission message buffer descriptor it is needed
 * to initialize, configure and start a CAN controller
 **/
typedef struct
{
    /**
     * @brief INPUT: Host defined tag used to track a specific frame.
     *
     * This field is not changed by the HSCG firmware and is returned
     * back to the host as it is.
     * See \link Hscg_Can_Tx2HostAckInfoType \endlink
     */
    uint16 u16FrameTag1;
    /**
     * @brief INPUT: Host defined tag used to track a specific frame.
     *
     * This field is not changed by the HSCG firmware and is returned back
     * to the host as it is.
     * See \link Hscg_Can_Tx2HostAckInfoType \endlink
     */
    uint16 u16FrameTag2;
    /**
     * @brief OUTPUT: Index to the frame message buffer.
     * See \link Hscg_Can_MbType \endlink
     */
    uint16 u16MbFrameIdx;
    /**
     * @brief INPUT: Host defined interface used to select the acknowledge
     * interface of a specific frame.
     *
     * This field is not changed by the HSCG firmware.
     */
    uint8 u8AckInterface;
    /**
     * @brief INPUT: Request firmware to add MAC code to the transmitted
     * frame payload.
     */
    uint8 u8EnableTxFrameMac;
} __HSCG__ALIGNED__PACKED__ Hscg_Can_TxMbDescriptorType;

/**
 * @brief Acknowledge transmission information send from HSCG to host.
 *
 * It is used in order to send from HSCG to host needed information in order to
 * identify and confirm that a specific frame was transmitted on the CAN bus.
 * This data structure type is used in order to implement a circular buffer for
 * each channel which is accessed by using indexes transferred from HSCG to host
 * by using TXACK FIFOs.
 * This approach allows usage of existing hardware FIFOs even the size of the
 * transferred data is higher than the FIFO element width size.
 *
 * @pre Before to read any acknowledge information, it is needed to do a
 * transmission request.
 **/
typedef struct
{
    /** @brief OUTPUT: Transmission time stamp.*/
    uint32 u32TxTimestamp;
    /**
     * @brief OUTPUT: Host defined tag used to track a specific frame.
     * This field is not changed by the HSCG firmware and is returned back
     * to the host as it is.
     * See \link Hscg_Can_TxMbDescriptorType \endlink
     */
    uint16 u16FrameTag1;
    /**
     * @brief OUTPUT: Host defined tag used to track a specific frame.
     * This field is not changed by the HSCG firmware and is returned back
     * to the host as it is.
     * See \link Hscg_Can_TxMbDescriptorType \endlink
     */
    uint16 u16FrameTag2;
} __HSCG__ALIGNED__PACKED__ Hscg_Can_Tx2HostAckInfoType;

/**
 * @brief Command for polling of controller state .
 * @details  It is send from host to HSCG to query it for the controller state.
 *
 **/
typedef struct
{
    /** @brief OUTPUT: Current state of the CAN controller. */
    Hscg_Can_CtrlStateType eControllerState;
} __HSCG__ALIGNED__PACKED__  Hscg_Can_GetControllerModeCmdType;

/**
 * @brief Set controller mode command.
 *
 * It is send from host to HSCG module in order request changing the state of a
 * CAN controller. Currently it allows only to start and stop a controller.
 * When a controller is started it allows to transmit and receive frames from
 * the bus. When the controller is stopped it ignores all frames from the bus
 * and it doesn't transmit any frame.
 *
 * @pre Before changing the controller state it must be initialized.
 **/
typedef struct
{
    /** @brief INPUT: The new state which is requested. */
    Hscg_Can_StateTransitionType eTransition;
} __HSCG__ALIGNED__PACKED__ Hscg_Can_SetControllerModeCmdType;

/**
 * @brief Data baud rate settings for a CAN FD controller.
 *
 * It is used to configure the CAN FD settings including baud rate used during
 * data phase.
 **/
typedef struct
{
    /**
     * @brief INPUT: Configuration of data phase baud rate:
     * - Prescaler divisor: (bit 23-27)
     * - Resynchronization Jump Width: (bit 16-19)
     * - Time Segment 2: (bit 9-12)
     * - Time Segment 1: (bit 0-4)
     *
     * Each parameter value shall be decreased by 1 when it is written into
     * this data structure field.
     */
    uint32 u32DataBaudrateConfig;
    /**
     * @brief INPUT: Enable or disable FD related features of the CAN
     * controller.
     */
    uint8 u8FdEnable;
    /**
     * @brief INPUT: Enable or disable baud rate switch (BRS) at the level
     * of CAN controller.
     */
    uint8 u8ControllerTxBitRateSwitch;
    /**
     * @brief INPUT: Enable or disable Transceiver Delay Compensation:
     * - TRUE: enabled
     * - FALSE: disabled.
     */
    uint8 u8TrcvDelayCompEnable;
    /**
     * @brief INPUT: Enable or disable Transceiver Delay Measurement:
     * - TRUE: enabled
     * - FALSE: disabled.
     *
     * When it is enabled, the secondary sample point is determined by the
     * sum of the transceiver delay measurement plus transceiver delay
     * compensation offset. When it is disabled, the secondary sample point
     * is determined only by the transceiver delay compensation offset.
     */
    uint8 u8TrcvDelayMeasEnable;
    /** @brief INPUT: Value of Transceiver Delay Compensation Offset*/
    uint8 u8TrcvDelayCompOffset;
} __HSCG__ALIGNED__PACKED__ Hscg_Can_ControllerFdConfigType;

/**
 * @brief Filter element settings.
 *
 * It is used to define a specific filter.Current filtering process suppose to
 * accept a frame if it's frame ID match the filter ID masked with the mask
 * value. At the end of filtering process an internal filter ID is mapped to
 * the accepted frame in order to track it later by the host software.
 * A maximum number of frames accepted by a specific filter can be managed
 * by HSCG at each point in time.
 **/
typedef struct
{
    /**
     * @brief INPUT:
     * - For MASK filters: Frame id mask value. Bit fields containing
     * \b 0 means don't care.
     * - For RANGE filters: Maximum accepted id value.
     * - For EXACT MATCH: not used.
     */
    uint32 uIdMask;
    /**
     * @brief INPUT:
     * - For MASK filters: CAN frame ID value.
     * - For RANGE filters: Minimum accepted id value.
     * - For EXACT MATCH: id value
     */
    uint32 uMessageId;
    /**
     * @brief INPUT: Filter identifier used to track frames after filtering
     * process on the reception side.
     * See also \link Hscg_Can_RxMbDescriptorType \endlink
     */
    uint16 u16FilterId;
    /**
     * @brief INPUT: Maximum number of message buffers which can be used to
     * store frames accepted by this filter at each specific point in time.
     * When the maximum value is reached the firmware will begin to drop the
     * received frames accepted by that filter.It is used also in order to
     * prevent that the frames accepted by a specific filter do not overload
     * the HSCG internal hardware resources (e.g. message buffers, FIFOs).
     */
    uint16 u16MbCount;
    /**
     * @brief INPUT: Reception interface id used to deliver frames accepted
     * by that filter to the host.
     */
    uint8 u8RxDestInterface;
    /** @brief INPUT: Filter entry type: mask, range, exact match */
    Hscg_Can_EntryType eEntryType;
    /**
     * @brief OUTPUT: Filter address inside hardware filtering accelerator
     * where the filter fields are stored.
     *
     * Host side application can use this to track used filter entries.
     * The search operation start from low filter addresses and continue to
     * the high filter addresses.
     */
    uint16 u16FilterAddr;
} __HSCG__ALIGNED__PACKED__ Hscg_Can_ReceiveFilterType;



typedef struct{
    uint32 id;
    uint32 u32Can2CanRoutingOptions;    // EDL IDE BRS
    uint32 u32CanIdRemapValue;
    uint32 RouteCount:4;
    uint32 RouteNum0:4;
    uint32 RouteNum1:4;
    uint32 RouteNum2:4;
    uint32 RouteNum3:4;
    uint32 RouteNum4:4;
    uint32 RouteNum5:4;
    uint32 RouteNum6:4;
    uint8  u8DestHwChList[HSCG_CAN_CONFIG_MAXCTRL_COUNT];
} Hscg_Can_EnhancedFilterType;



typedef struct
{
    uint32 filter;
    uint32 mask;
    uint32 u32Can2CanRoutingOptions;    // EDL IDE BRS
    uint32 u32CanIdRemapValue;
    uint32 RouteCount:4;
    uint32 RouteNum0:4;
    uint32 RouteNum1:4;
    uint32 RouteNum2:4;
    uint32 RouteNum3:4;
    uint32 RouteNum4:4;
    uint32 RouteNum5:4;
    uint32 RouteNum6:4;
    uint8  u8DestHwChList[HSCG_CAN_CONFIG_MAXCTRL_COUNT];
} Hscg_Can_EnhancedExtFilterType;

typedef struct
{
    uint32 filter;
    uint32 mask;
    uint32 u32Can2CanRoutingOptions;    // EDL IDE BRS
    uint32 u32CanIdRemapValue;
    uint32 RouteCount:4;
    uint32 RouteNum0:4;
    uint32 RouteNum1:4;
    uint32 RouteNum2:4;
    uint32 RouteNum3:4;
    uint32 RouteNum4:4;
    uint32 RouteNum5:4;
    uint32 RouteNum6:4;
    uint8  u8DestHwChList[HSCG_CAN_CONFIG_MAXCTRL_COUNT];
} Hscg_Can_EnhancedStdFilterType;




typedef struct
{
    uint32 ExtCount;
    uint32 StdCount;
    Hscg_Can_EnhancedFilterType *pExtFilter;
    Hscg_Can_EnhancedFilterType *pStdFilter;
} Hscg_Can_EnhancedRxFifoFilterType;


/**
 * @brief CAN to CAN routing filter configuration.
 *
 * It is used to define a specific routing filter. Current routing
 * implementation suppose to accept a received frame for a specific
 * ID and ID mask combination, then route that frame to one or more transmission
 * channels.
 **/
typedef struct
{
    /** @brief INPUT: Special option for advanced routing.*/
    uint32 u32Can2CanRoutingOptions;
    /** @brief INPUT: Can Id Remap Value.*/
    uint32 u32CanIdRemapValue;
    /**
     * @brief INPUT: List of destination CAN controllers for the
     * accepted frame.
     */
    uint8 u8DestHwChList[HSCG_CAN_CONFIG_MAXCTRL_COUNT];
    /** @brief INPUT: Length of the destination CAN controller list.*/
    uint8 u8DestHwChListCount;
} __HSCG__ALIGNED__PACKED__ Hscg_Can_Can2CanRoutingTableType;

/**
 * @brief Data structure type containing CAN to Ethernet destination rule
 * configuration.
 *
 * It is used to define a specific destination rule for Can2Eth internal
 * routing.
 **/
typedef struct
{
    /** @brief   INPUT: Base address of the buffer area for this destination */
    uint32 pu8Can2EthBuffAddr;
    /** @brief   INPUT: Size of each buffer for this destination */
    uint16 u16Can2EthBuffSize;
    /** @brief   INPUT: Number of buffers of size u16Can2EthBuffSize for this destination */
    uint8  u8Can2EthBuffCount;
    /**
     * @brief INPUT: Ethernet MAC destination address as it is defined by
     * IEEE 802.3 standard.
     */
    uint8 u8Can2EthDestMac[6];
} __HSCG__ALIGNED__PACKED__ Hscg_Can_Can2EthRoutingTableType;

/**
 * @brief Data structure type representing  destination rule used by Advanced
 * Features(AF)
 *
 * Used to hold a generic type of AF destination rule
 **/
typedef struct
{
    /** @brief Destination rule content.*/
    union {
        /**
         * @brief INPUT: Destination rule for Can2Can internal routing
         * use case.
         */
        Hscg_Can_Can2CanRoutingTableType Can2Can;
        /** @brief INPUT: Destination rule for Can2Eth use case.*/
        Hscg_Can_Can2EthRoutingTableType Can2Eth;
    } AfDest;
    /** @brief INPUT: Destination rule type.*/
    Hscg_Af_RuleIdType eAfDestId;
} __HSCG__ALIGNED__PACKED__ Can_Af_DestRulesType;

/**
 * @brief Advanced filter configuration.
 *
 * It is used to define an advanced filter. It contains references to the
 * individual features configured by the host.
 **/
typedef struct
{
    /** @brief INPUT: Option for frame authentication feature. */
    Hscg_Af_AuthenticationOptionsType eCanAuthenticationFeature;
    /** @brief INPUT: Option for host receive feature. */
    Hscg_Can_HostReceiveOptionsType eHostReceive;
    /** @brief INPUT: Option for logging feature. */
    Hscg_Af_LoggingOptionsType eCanLoggingFeature;
    /**
     * @brief INPUT: CAN2CAN routing table index.
     * Reference to the routing table rule.
     * See \link Hscg_Can_Can2CanRoutingTableType \endlink
     */
    uint8 u8Can2CanRoutingTableIdx;
    /**
     * @brief INPUT: CAN2ETH routing table index.
     * Reference to the routing table rule.
     * See \link Hscg_Can_Can2EthRoutingTableType \endlink
     */
    uint8 u8Can2EthRoutingTableIdx;
} __HSCG__ALIGNED__PACKED__ Hscg_Can_AdvancedFeatureType;


/**
 * @brief Configurable errors that HSCG Firmware handles.
 *
 * Configurable errors that HSCG Firmware handles using different types of
 * processing.It is part of platform initialization command.
 * Only BusOff processing type is selectable per channel.
 **/
typedef struct
{
    /** @brief CAN Protocol errors supported by CAN controller. */
    Hscg_Can_ErrorProcessingType eCanProtocolErr;
    /** @brief DATALOST event as described by Autosar standard */
    Hscg_Can_ErrorProcessingType eDataLostErr;
    /**
     * @brief Initialization errors, like resources overflow, bad commands
     * flow, bad command parameters, invalid indexes or any other errors
     * caused by bad usage or a malicious host.
     */
    Hscg_Can_ErrorProcessingType eInitErr;
    /** @brief Internal errors, like timeouts. */
    Hscg_Can_ErrorProcessingType eInternalErr;
    /** @brief BusOff processing is selectable per channel */
    Hscg_Can_ErrorProcessingType eBusOffErr[HSCG_CAN_CONFIG_MAXCTRL_COUNT];
} __HSCG__ALIGNED__PACKED__ Hscg_Can_ErrorCategoryType;

/**
 * @brief Platform initialization command.
 *
 * It is sent by the host to HSCG in order to configure the platform related
 * parameters. It is the first command which shall be send to HSCG module after
 * booting in order to configure common HSCG components.
 * Most important operations done by HSCG firmware at platform initialization
 * are:
 * - initializes all common internal HSCG components (hardware and software).
 * - prepare filter management data structures
 **/
typedef struct
{
    /**
     * @brief INPUT: Array containing the initialization status of the
     * controllers
     */
    Hscg_Can_StatusType eCtrlInitStatus[HSCG_CAN_CONFIG_MAXCTRL_COUNT];
} __HSCG__ALIGNED__PACKED__ Hscg_Can_InitPlatformCmdType;

/**
 * @brief Initialization command.
 *
 * It is sent by the host to HSCG in order to load and configure all needed
 * parameters inside HSCG. 
 * Most important operations done by HSCG firmware at initialization are:
 * - when this command is executed for the first CAN channel it initialize also
 * all internal HSCG components.
 * - configure the hardware features of a CAN controller.
 * - set a CAN controller in the stop state.
 **/
typedef struct
{
    /**
     * @brief INPUT: Configuration options for a hardware CAN controller.
     * See \link HSCG_CAN_CONTROLLERCONFIG_CTRL_EN_U32 \endlink as a
     * controller  option example
     */
    uint32 u32CtrlConfig;
} __HSCG__ALIGNED__PACKED__ Hscg_Can_InitCmdType;

/**
 * @brief HSCG-PFE Initialization command.
 *
 * It is sent by the host to HSCG in order to activate the HSCG-PFE interface,
 * and obtain the addresses of the relevant data structures.
 * @note Use uint32 instead of void*, for portability
 **/
typedef struct
{
    /** @brief OUTPUT: Address of the PFE RX Ring in HSCG memory */
    uint32 pRxRing;
    /** @brief OUTPUT: Address of the PFE RX Writeback Ring in HSCG memory
     */
    uint32 pRxWbRing;
    /** @brief OUTPUT: Address of the PFE TX Ring in HSCG memory */
    uint32 pTxRing;
    /** @brief OUTPUT: Address of the PFE TX Writeback Ring in HSCG memory */
    uint32 pTxWbRing;
} __HSCG__ALIGNED__PACKED__ Hscg_Can_InitPfeCmdType;

/**
 * @brief Get status command.
 *
 * It is send by the host to HSCG in order to get the content of all status
 * registers of a specific CAN controller. This command makes only a read
 * operation on the status registers of CAN controller.
 **/
typedef struct
{
    /** @brief OUTPUT: Register ECR of CAN controller. */
    uint32 u32ECR;
    /** @brief OUTPUT: Register ISR of CAN controller. */
    uint32 u32ISR;
    /** @brief OUTPUT: Register SR of CAN controller. */
    uint32 u32SR;
    /** @brief OUTPUT: Register CRC of CAN controller. */
    uint32 u32CRC;
} __HSCG__ALIGNED__PACKED__ Hscg_Can_GetStatusCmdType;

/**
 * @brief Get firmware version command.
 *
 * It is send by the host to HSCG in order to get the firmware version string.
 * It is copied in the response.
 **/
#define HSCG_VERSION_MAX_LENGTH 50
typedef struct
{
    /** @brief OUTPUT: HSCG FW version string actual length. */
    uint8 stringLength;
    /** @brief OUTPUT: HSCG FW version string. */
    uint8 versionString[HSCG_VERSION_MAX_LENGTH];
} __HSCG__ALIGNED__PACKED__ Hscg_Can_GetFwVersionType;

/**
 * @brief Remove filter command structure.
 *
 * It is send by the host to HSCG in order to remove a specific filter
 * identified by a hardware address.
 **/
typedef struct
{
    /**
     * @brief INPUT: Address of the filter which shall be
     * removed/disabled.
     */
    uint16 u16FilterAddr;
} __HSCG__ALIGNED__PACKED__ Hscg_Can_RemoveFilterType;

/**
 * @brief Add AF destination command structure.
 *
 * It is send by the host to HSCG in order add a destination to be used by AF
 **/
typedef struct
{
    /** @brief INPUT: Destination to add to the list */
    Can_Af_DestRulesType rule;
    /** @brief OUTPUT: Index in HSCG list where destination was inserted */
    uint8 u8Idx;
} __HSCG__ALIGNED__PACKED__ Hscg_Can_CreateAfDestination;

/**
 * @brief Abort MB command structure
 *
 * It is send by the host to HSCG in order to abort the lowest priority pending
 * transmission of a specific controller.
 **/
typedef struct
{
    /**
     * @brief INPUT: Host defined tag used to track a specific frame.
     * See \link Hscg_Can_TxMbDescriptorType \endlink
     */
    uint16 u16FrameTag;
    /** @brief   OUTPUT: Number of Tx pending transmissions aborted */
    uint8 u8AbortedFrameCnt;
    /** @brief INPUT: Specifies the type of AbortMB command. */
    Hscg_Can_AbortMbType eAbortMbType;
} __HSCG__ALIGNED__PACKED__ Hscg_Can_AbortMbCmdType;

/**
 * @brief List of commands used by host.
 *
 * It is used in order to use the same memory area for all commands send from
 * host to HSCG.
 **/
union Hscg_Can_CommandListType {
    /** @brief Command for initializing a specific CAN channel. */
    Hscg_Can_InitCmdType Init;
    /**
     * @brief Command for getting the hardware status information for a
     * specific CAN controller.
     */
    Hscg_Can_GetStatusCmdType GetStatus;
    /**
     * @brief Command for getting the status of a specific CAN controller.
     */
    Hscg_Can_GetControllerModeCmdType GetControllerMode;
    /**
     * @brief Command for changing the status of a specific CAN controller.
     */
    Hscg_Can_SetControllerModeCmdType SetControllerMode;
    /** @brief Command for getting the firmware version. */
    Hscg_Can_GetFwVersionType GetFwVersion;
    /**
     * @brief Command for configuring platform related parameters and common
     * HW components used by all CAN channels
     */
    Hscg_Can_InitPlatformCmdType InitPlatform;
    /**
     * @brief Command for initializing the HSCG-PFE interface and getting
     * buffer locations
     */
    Hscg_Can_InitPfeCmdType InitPfe;
    /** @brief Command for removing/disable a single filter. */
    Hscg_Can_RemoveFilterType RemoveFilter;
    /** @brief Command for creating a destination for AF */
    Hscg_Can_CreateAfDestination CreateAfDest;
    /**
     * @brief Command for aborting either the lowest priority message buffer
     * or all the message buffers with a specific tag.
     */
    Hscg_Can_AbortMbCmdType AbortMb;
};

/**
 * @brief Command used by host.
 *
 * It is used in order to send commands from host to HSCG using shared memory.
 **/
typedef struct
{
    /** @brief INPUT: Command parameters. */
    union Hscg_Can_CommandListType CmdList;
    /** @brief INPUT: Command ID. */
    Hscg_Can_CommandIdType eCmdId;
    /** @brief OUTPUT: Return status code after command completion.*/
    Hscg_Fw_ReturnType eReturnValue;
} __HSCG__ALIGNED__PACKED__ Hscg_Can_CommandType;

/**
 * @brief Set controller mode notification.
 *
 * Notification send from HSCG to host in order to inform about a specific
 * controller state change.
 **/
typedef struct
{
    /**
     * @brief OUTPUT: Current state of the CAN controller.
     * See also \link Hscg_Can_CtrlStateType \endlink
     */
    Hscg_Can_CtrlStateType eControllerState;
    /** @brief OUTPUT: CAN controller id. */
    uint8 u8HwCtrl;
} __HSCG__ALIGNED__PACKED__ Hscg_Can_CtrlModeNotifType;

/**
 * @brief Platform specific error.
 *
 * Platform error details send to host in order to report an internal
 * HSCG error.
 **/
typedef struct
{
    /**
     * @brief OUTPUT: HSCG firmware component id.
     * See also \link Hscg_Can_ModuleType \endlink
     */
    Hscg_Can_ModuleType eModuleId;
    /**
     * @brief OUTPUT: HSCG error code.
     * See also \link Hscg_Fw_ReturnType \endlink
     */
    Hscg_Fw_ReturnType eErrorCode;
    /** @brief OUTPUT: Number of ocurrences of the last error. */
    uint8 u8ErrorCount;
} __HSCG__ALIGNED__PACKED__ Hscg_Can_ErrorNotifType;

/** @brief Channel specific error.
 *
 * Channel error details send to host in order to report an internal HSCG error.
 **/
typedef struct
{
    Hscg_Can_ErrorNotifType ErrorInfo;
    /** @brief OUTPUT: Controller ID. */
    uint8 u8HwCtrl;
} __HSCG__ALIGNED__PACKED__ Hscg_Can_ChannelErrorNotifType;

/**
 * List of notifications send by HSCG to host, used by host.
 *
 * It is used by HSCG to notify host about specific events inside HSCG.
 **/
union Hscg_Can_NotificationListType {
    /**
     * @brief OUTPUT: Notification parameters for controller state changes.
     * See also \link Hscg_Can_CtrlModeNotifType \endlink
     */
    Hscg_Can_CtrlModeNotifType CtrlMode;
    /**
     * @brief OUTPUT: Notification parameters for platform errors.
     * See also \link Hscg_Can_ErrorNotifType \endlink
     */
    Hscg_Can_ErrorNotifType PlatformError;
    /**
     * @brief OUTPUT: Notification parameters for channel errors.
     * See also \link Hscg_Can_ChannelErrorNotifType \endlink
     */
    Hscg_Can_ChannelErrorNotifType ChannelError;
};

/**
 * @brief Notifications used by HSCG.
 *
 * It is used in order to send notifications from HSCG to host by using shared
 * memory.
 **/
typedef struct
{
    /**
     * @brief OUTPUT: Notification parameters.
     * See also \link Hscg_Can_NotificationListType \endlink
     */
    union Hscg_Can_NotificationListType NotifList;
    /**
     * @brief OUTPUT: Notification ID.
     * See also \link Hscg_Can_NotificationIdType \endlink
     */
    Hscg_Can_NotificationIdType eNotifId;
} __HSCG__ALIGNED__PACKED__ Hscg_Can_NotificationType;

/**
 * @brief Notification tables.
 *
 * Notification tables used to store the details of the notifications.
 * The index of entries are send to host cores.The two tables are related to
 * reporting method:interrupt or polling.
 **/
typedef struct
{
    /**
     * @brief OUTPUT: Table used to report notifications in interrupt mode.
     * See also \link Hscg_Can_NotificationType \endlink
     */
    Hscg_Can_NotificationType
        Can_aNotif0_Table[HSCG_CAN_CONFIG_HIF_COUNT]
                         [HSCG_CAN_CONFIG_NOTIF_TABLE_SIZE];
    /**
     * @brief OUTPUT: Table used to report notifications in polling mode.
     * See also \link Hscg_Can_NotificationType \endlink
     */
    Hscg_Can_NotificationType
        Can_aNotif1_Table[HSCG_CAN_CONFIG_HIF_COUNT]
                         [HSCG_CAN_CONFIG_NOTIF_TABLE_SIZE];
} __HSCG__ALIGNED__PACKED__ Hscg_Can_NotificationTableType;

/**
 * @brief Shared memory structure
 *
 * Structure that encapsulates all the shared memory with HSCG on the CAN side.
 **/
typedef struct
{
    /** @brief Receive message buffer descriptors. */
    Hscg_Can_RxMbDescriptorType Can_Rx_aMbDesc[HSCG_CAN_CONFIG_MAXRXMB];
    /** @brief Transmit message buffer descriptors. */
    Hscg_Can_TxMbDescriptorType Can_Tx_aMbDesc[HSCG_CAN_CONFIG_MAXTXMB];
    /** @brief Shared memory used store the CAN message buffers. */
    Hscg_Can_MbType Can_aMb[HSCG_CAN_CONFIG_MAXTXMB + HSCG_CAN_CONFIG_MAXRXMB +
                            HSCG_CAN_CONFIG_MAXAFFRMB];
    /** @brief Shared memory used to send commands from Host to HSCG . */
    Hscg_Can_CommandType aCanCmd[HSCG_CAN_CONFIG_MAXCTRL_COUNT];
    /** @brief Shared memory used to store notifications from HSCG to host.
     */
    Hscg_Can_NotificationTableType Can_NotificationTable;
    /**
     * @brief Circular buffer used to send ACK info from TX core to HOST
     * core. Reserved 1 extra buffer for each interface for consistency
     * purposes.
     */
    Hscg_Can_Tx2HostAckInfoType Can_Tx_aAckInfo[HSCG_CAN_CONFIG_MAX_TXACKINFO];
} __HSCG__ALIGNED__PACKED__ Hscg_Can_SharedMemoryType;

/*==================================================================================================
*                                GLOBAL VARIABLE DECLARATIONS
==================================================================================================*/

/*==================================================================================================
*                                    FUNCTION PROTOTYPES
==================================================================================================*/

#ifdef __cplusplus
}
#endif

#endif /*HSCG_INTERFACECANTYPES_H*/

/** @} */
